﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SystemHelperLibrary.Images
{
	using System.Drawing;
	using System.Drawing.Imaging;

	public class Filters
	{
		//Gilles Khouzams colour corrected grayscale shear
		static ColorMatrix cm = new ColorMatrix(new float[][]{   
                                   new float[]{0.3f,  0.3f, 0.3f,  0,  0},
                                   new float[]{0.59f,0.59f,0.59f,  0,  0},
                                   new float[]{0.11f,0.11f,0.11f,  0,  0},
                                   new float[]{0,  0,    0,    1,  0,  0},
                                   new float[]{0,  0,    0,    0,  1,  0},
                                   new float[]{0,  0,    0,    0,  0,  1}});

		public static Image ToGrayScale(Image img)
		{
			//BobPowell.Net
			//http://www.bobpowell.net/grayscale.htm
			Graphics g = Graphics.FromImage(img);
			ImageAttributes ia = new ImageAttributes();
			ia.SetColorMatrix(cm);
			g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
			g.Dispose();
			return img;
		}

	}
}
